package com.xnfh.planting.viewmodel

import com.xnfh.common.bean.FieldListBean
import com.xnfh.framework.base.BaseViewModel
import com.xnfh.framework.bean.RespStateData
import org.json.JSONObject

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2023/12/7 17:04
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/12/7 17:04
 * @UpdateRemark: 更新说明
 */
class PlantingViewModel: BaseViewModel() {

    private val plantingViewModelRes = PlantingViewModelRes()
    val fieldListData = RespStateData<FieldListBean>()

    /**
     * 获取地块列表
     * @param
     */
    fun requestFieldList(page: Int, searchKey: String? = null) = launch {
        val jsonObject = JSONObject()
        jsonObject.put("current", page)
        jsonObject.put("size", 20)
        if(!searchKey.isNullOrEmpty()){
            jsonObject.put("fieldName", searchKey)
        }
        plantingViewModelRes.requestFieldList(creatRequestBody(jsonObject.toString()), fieldListData)
    }
}